<?php

namespace Trawind\Events\Subscribers\Sale\Cabinet;

use Trawind\Events\Events\Purchase\ReceivePurchaseEvent;
use Trawind\Events\Events\Sale\Cabinet\DeleteCabinetEvent;
use Trawind\Events\Events\Sale\Cabinet\StoreCabinetEvent;
use Trawind\Events\Events\Sale\Dispatch\ReceiveVehicleEvent;
use Trawind\Extension\Models\Deploy\BusinessType;

class CabinetSubscriber
{
    private $businessType = \Trawind\Basics\Enums\BusinessType::SALE_CABINET_LOGISTIC_CABINET;


    public function receivePurchase($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, ReceivePurchaseEvent::class);
        }
    }

    public function receiveVehicle($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, ReceiveVehicleEvent::class);
        }
    }

    /**
     *
     * @param  \Illuminate\Events\Dispatcher  $events
     */
    public function subscribe($events)
    {
        $events->listen(
            ReceivePurchaseEvent::class,
            static::class . '@receivePurchase'
        );

        $events->listen(
            ReceiveVehicleEvent::class,
            static::class . '@receiveVehicle'
        );

    }
}
